package org.one.stone.soup.grfxML.plugin.control;


import org.one.stone.soup.grfxML.GrfxMLEngine;
import org.one.stone.soup.grfxML.plugin.SimplePlugin;
import org.one.stone.soup.grfxML.plugin.grfxMLCaster;
import org.one.stone.soup.mjdb.data.field.DataLinker;
import org.one.stone.soup.mjdb.data.field.Field;
import org.one.stone.soup.mjdb.data.field.LockException;

public class Scaler extends SimplePlugin {


	public static final int ARG_SCALE = 0;

	public static final int ARG_ZOOMIN = 1;

	public static final int ARG_ZOOMOUT = 2;



	org.one.stone.soup.grfxML.DataScale scale = new org.one.stone.soup.grfxML.DataScale();

	org.one.stone.soup.grfxML.DataState zoomIn = new org.one.stone.soup.grfxML.DataState();

	org.one.stone.soup.grfxML.DataState zoomOut = new org.one.stone.soup.grfxML.DataState();

	float ds = 0;
/**
 * Scaler constructor comment.
 */
public Scaler (GrfxMLEngine engine){
	super(engine);
}
/**
 * initialize method comment.
 */
public void initialize() {}
/**
 * process method comment.
 */
public void process()
{
 try{

	boolean scaleChanged = false;

	if(zoomIn.getValue()==true)
	{
		ds+=0.1;
		scaleChanged=true;
	}
	if(zoomOut.getValue()==true)
	{
		ds-=0.1;
		scaleChanged=true;
	}

	if(scaleChanged)
	{
		if(ds>=0)
		{
			scale.setValue( (float)(ds+1),this );
		}
		else
		{
			scale.setValue( (float)1/(1-ds),this );
		}
	}

 }catch(LockException le){}
}
/**
 * register method comment.
 */
public void register(DataLinker store)
{

	scale = grfxMLCaster.cast(scale,getArg(scale,ARG_SCALE,store));

	zoomIn = grfxMLCaster.cast(zoomIn,getArg(zoomIn,ARG_ZOOMIN,store));

	zoomOut = grfxMLCaster.cast(zoomOut,getArg(zoomOut,ARG_ZOOMOUT,store));

}
/**
 * replace method comment.
 */
public void replace(Field oldObj, Field newObj)
{

	scale = grfxMLCaster.replace(scale,oldObj,newObj);

	zoomIn = grfxMLCaster.replace(zoomIn,oldObj,newObj);

	zoomOut = grfxMLCaster.replace(zoomOut,oldObj,newObj);

}
/**
 * stop method comment.
 */
public void stop() {}
}
